package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Category;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author Login
 * @since 2025-07-17
 */
@Tag(name = "分类品牌")
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {

    @Autowired
    private ICategoryBrandService categoryBrandService;


    @Operation(summary = "查询品牌分页列表")
    @GetMapping("/list")
    public TableDataInfo list(CategoryBrand categoryBrand) {
        startPage();
        List<CategoryBrand> list = categoryBrandService.selectCategoryBrandlList(categoryBrand);
        return getDataTable(list);
    }

    @Operation(summary = "新增品牌分类")
    @PostMapping
    public AjaxResult add(@RequestBody CategoryBrand categoryBrand) {
        categoryBrand.setCreateBy(SecurityUtils.getUsername()); //由谁创建的
        return toAjax(categoryBrandService.insertCategoryBrand(categoryBrand));
    }

    @Operation(summary = "删除品牌分类")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(
            @Parameter(description = "品牌分类id")
            @PathVariable List<Long> ids) {

        return toAjax(categoryBrandService.removeBatchByIds(ids));
    }

    @Operation(summary = "信息回显")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(categoryBrandService.selectCategoryBrandById(id));
    }
    @Operation(summary = "修改品牌")
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryBrand categoryBrand) {
        categoryBrand.setCreateBy(SecurityUtils.getUsername());
        return toAjax(categoryBrandService.updateCategoryBrand(categoryBrand));
    }

    @Operation(summary = "根据分类id查询品牌列表")
    @GetMapping("/brandList/{categoryId}")
    public AjaxResult selectBrandListByCategoryId(
            @Parameter (description = "分类id")
            @PathVariable Long categoryId
    ){
        return success(categoryBrandService.selectBrandListByCategoryId(categoryId));
    }

}
